<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>添加角色</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" id="roleId" name="roleId">
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>角色名称:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input roleName" lay-verify="required" placeholder="请输入角色名称">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label"><span style="color:red;">*</span>角色描述:</label>
		<div class="layui-input-block">
			<textarea placeholder="请输入角色描述" lay-verify="required" class="layui-textarea roleDepict"></textarea>
		</div>
	</div>
	<div class="layui-layer-btn layui-layer-btn-">
	    <button class="layui-btn" lay-submit="" lay-filter="addRole">确认</button>
	    <button type="reset" class="layui-btn layui-btn-primary" onclick="close_self();">取消</button>
	 </div>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    form.on("submit(addRole)",function(data){
    	var url =""; var record ="";
    	if($("#roleId").val() != ""){
    		url="/admin/role/update";
    		record ="编辑角色:";
    	}else{
    		url="/admin/role/insert";
    		record ="新增角色:";
    	}
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post(url,{
        	roleId : $("#roleId").val(),
        	roleName : $(".roleName").val(),
        	roleDepict : $(".roleDepict").val(),
        	record : record
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功！");
  	            setTimeout(function(){
  	            	var index = parent.layer.getFrameIndex(window.name);
  	            	parent.layer.close(index);
  	            },2000); 
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })
    
})

function close_self() {
    var index=parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
</script>
</body>
</html>